package com.triplelink.util;

import com.triplelink.annotations.ClassType;
import com.triplelink.builder.query.QueryTL;
import com.triplelink.exception.TripleLinkException;

public class ClassTypeUtil
{
	public static void putClassType(Object currentEntity, String id, QueryTL query)
	{
		Class<?> currentClass = currentEntity.getClass();
		
		while (currentClass != null)
		{
			ClassType classType = currentEntity.getClass().getAnnotation(ClassType.class);
			
			if (classType != null)
			{
				query.appendInstanceType(id, classType.type());
				return;
			}
			
			currentClass = currentClass.getSuperclass();
		}
		
		throw new TripleLinkException(
				"The Class " + currentEntity.getClass().getName() +
				" doesn't have annotation " + ClassType.class.getName()
		);
	}
}